home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / virus / stelth22.zip / DOSMCB.PAS < prev    next >
Pascal/Delphi Source File  |  1992-02-10  |  2KB  |  115 lines

  1. {
  2. dosmcb.pas
  3. Stealth Bomber Version 2.2
  4.  
  5. Kevin Dean
  6. Fairview Mall P.O. Box 55074
  7. 1800 Sheppard Avenue East
  8. Willowdale, Ontario
  9. CANADA    M2J 5B9
  10. CompuServe ID: 76336,3114
  11.  
  12. February 10, 1992
  13.  
  14.     This module handles the DOS memory control block interface.
  15.  
  16.     This code is public domain.
  17. }
  18.  
  19.  
  20. unit DOSMCB;
  21.  
  22.  
  23. interface
  24.  
  25.  
  26. uses
  27.   DOS;
  28.  
  29.  
  30. type
  31.   MCB =
  32.     record
  33.     ID : byte;        { MCB ID ($4D for all but last which is $5A). }
  34.     PSP : word;        { PSP of the program that owns the block. }
  35.     Size : word;    { Size of allocated memory in paragraphs. }
  36.     end;
  37.   MCBPtr =
  38.     ^MCB;
  39.  
  40.  
  41. function GetMCB : MCBPtr;
  42. function NextMCB(ThisMCB : MCBPtr) : MCBPtr;
  43. function MCBOwner(Ptr : pointer) : MCBPtr;
  44.  
  45.  
  46. implementation
  47.  
  48.  
  49. type
  50.   WordPtr =
  51.     ^word;
  52.  
  53.  
  54. {***}
  55. { Get the first DOS memory control block. }
  56. function GetMCB : MCBPtr;
  57.  
  58. var
  59.   Regs : Registers;
  60.  
  61. begin
  62. { DOS function $52 gets the DOS list of lists. }
  63. Regs.AH := $52;
  64. MSDos(Regs);
  65.  
  66. { The first MCB pointer is two bytes behind the list of lists. }
  67. GetMCB := Ptr(WordPtr(Ptr(Regs.ES, Regs.BX - 2))^, 0);
  68. end;
  69.  
  70.  
  71. {***}
  72. { Get the next DOS memory control block. }
  73. function NextMCB(ThisMCB : MCBPtr) : MCBPtr;
  74.  
  75. begin
  76. if ThisMCB^.ID = $5A then
  77.   NextMCB := nil
  78. else
  79.   { Next MCB is Size + 1 paragraphs away. }
  80.   NextMCB := Ptr(Seg(ThisMCB^) + ThisMCB^.Size + 1, 0);
  81. end;
  82.  
  83.  
  84. {***}
  85. { Determine the owner of a particular pointer. }
  86. function MCBOwner(Ptr : pointer) : MCBPtr;
  87.  
  88. var
  89.   PSeg : word;
  90.   MCB : MCBPtr;
  91.  
  92. begin
  93. { Determine true segment. }
  94. PSeg := Seg(Ptr^) + Ofs(Ptr^) shr 4;
  95.  
  96. MCB := GetMCB;
  97.  
  98. { Pointer is invalid if below DOS memory. }
  99. if PSeg < Seg(MCB^) then
  100.   MCB := nil;
  101.  
  102. { Find pointer's MCB if it exists. }
  103. while (MCB <> nil) and (PSeg > Seg(MCB^) + MCB^.Size) do
  104.   MCB := NextMCB(MCB);
  105.  
  106. { Pointer cannot point within MCB itself. }
  107. if PSeg = Seg(MCB^) then
  108.   MCB := nil;
  109.  
  110. MCBOwner := MCB;
  111. end;
  112.  
  113.  
  114. end.
  115.